<html>

<style>
    .err{
        color:red;
    }
</style>
<body>
<?php
$nameErr = $emailErr = $websiteErr = $commentErr = $genderErr = "";
$name=$email=$website=$comment=$gender="";

function makesure($data) {
    $data = trim($data);
//    去掉空格和换行符
    $data = stripslashes($data);
//    去掉所有\
    $data = htmlspecialchars($data);
//    规范化
    return $data;
}
echo $_SERVER["REQUEST_METHOD"],PHP_EOL;
echo "输入数据规范化";
if ($_SERVER["REQUEST_METHOD"]=="POST")
{
    $name=makesure($_POST["name"]);
    $email=makesure($_POST["email"]);
    $website=makesure($_POST["website"]);
    $comment=makesure($_POST["comment"]);
    $gender=makesure($_POST["gender"]);
    if(empty($name))
    {
        $nameErr="name不能为空！";

    }
        else{$name=makesure($_POST["name"]);}

    if(empty($email))
    {
        $emailErr="email不能为空！";
    }
        else{$email=makesure($_POST["email"]);}

    if(empty($website))
    {
        $websiteErr="website不能为空！";
    }
        else{$website=makesure($_POST["website"]);}

    if(empty($comment))
    {
        $commentErr="comment可以为空";
    }
        else{$comment=makesure($_POST["comment"]);}

    if(empty($gender))
    {
        $genderErr="gender不能为空！";
    }
        else{$gender=makesure($_POST["gender"]);}


}




?>

<p class="err">带“*”的是必填字段</p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">

    name:<input type="text" name="name" value="<?php echo $name;?>">
    <span class="err"><?php echo "* ",$nameErr;?></span>
    <br><br>
    e-mail:<input type="text" name="email" value="<?php echo $email;?>">
    <span class="err"><?php echo "* ",$emailErr;?></span>
    <br><br>
    website:<input type="text" name="website" value="<?php echo $website;?>">
    <span class="err"><?php echo "* ",$websiteErr;?></span>
    <br><br>
    comment:<textarea name="comment" row="3" cols="30"><?php echo $comment;?></textarea>
    <?php echo $commentErr;?>
    <br><br>
    gender:
    <input type="radio" name="gender" <?php if($gender=="male") echo "checked";?> value="male">male
    <input type="radio" name="gender" <?php if($gender=="female") echo "checked";?> value="female">female
    <span class="err"><?php echo "* ",$genderErr;?></span>
    <br><br>
    <input type="submit" name="submit" value="submit">

</form>



</body>
</html>